package com.example.administrator.liveapp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.administrator.liveapp.R;
import com.example.administrator.liveapp.bean.LiveListBean;
import com.example.administrator.liveapp.utils.AppUrl;

import java.util.List;

/**
 * Created by Administrator on 2017/6/29 0029.
 */

public class LiveListPageAdapter extends RecyclerView.Adapter<LiveListPageAdapter.ViewHolder> implements View.OnClickListener{
    public List<LiveListBean.VideoBean> bean;
    public Context context;
    public LiveListPageAdapter(List<LiveListBean.VideoBean> bean) {
        this.bean = bean;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.live_list_recycler_item,null);
        ViewHolder viewHolder = new ViewHolder(view);
        context = parent.getContext();
        //将创建的View注册点击事件
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
//        if(bean.get(position).getPlaystatics().equals("0")){
//            holder.Live_state.setBackgroundResource(R.drawable.zhibozhong);
//        }else if(bean.get(position).getPlaystatics().equals("1")){
//            holder.Live_state.setBackgroundResource(R.drawable.huifang);
//        }else if(bean.get(position).getPlaystatics().equals("2")){
//            holder.Live_state.setBackgroundResource(R.drawable.yugao);
//        }
//        holder.Live_name.setText(bean.get(position).getVideoauthor());
//        holder.LiveList_views.setText(bean.get(position).getVideoviewcount());
//        holder.Live_title.setText(bean.get(position).getVideotitle());
//        String Url = bean.get(position).getVideoimgurl();
//        String ImageUrl = Url.substring(1, Url.indexOf("|"));
//        Glide.with(context)
//                .load(AppUrl.URL+ImageUrl)
//                .into(holder.LiveList_liveImage);
//        //将position保存在itemView的Tag中，以便点击时进行获取
//        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return bean.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView LiveList_liveImage;//直播背景图
        public ImageView Live_state;//视频状态(直播、回放、预约)
        public TextView Live_name;//直播人
        public TextView Live_time;//直播时间
        public TextView Live_title;//直播内容
        public RadioButton LiveList_views;
        public ViewHolder(View itemView) {
            super(itemView);
            LiveList_liveImage = (ImageView) itemView.findViewById(R.id.LiveList_liveImage);
            Live_state = (ImageView) itemView.findViewById(R.id.Live_state);
            Live_name = (TextView) itemView.findViewById(R.id.Live_name);
            Live_time = (TextView) itemView.findViewById(R.id.Live_time);
            Live_title = (TextView) itemView.findViewById(R.id.Live_title);
            LiveList_views = (RadioButton) itemView.findViewById(R.id.LiveList_views);
        }
    }

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {
            //注意这里使用getTag方法获取position
            mOnItemClickListener.onItemClick(v,(int)v.getTag());
        }
    }
    private OnItemClickListener mOnItemClickListener = null;

    //define interface
    public static interface OnItemClickListener {
        void onItemClick(View view , int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
}
